package com.cw.jeeyt.service.mq;

import org.apache.rocketmq.client.producer.SendStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import com.cw.mq.Producer;
import com.cw.mq.SendResult;
import com.cw.jeeyt.service.bo.api.ApiDatabaseBo;
import com.cw.jeeyt.core.intf.TimeoutProcessCore;
import com.cw.lang.common.utils.GsonUtil;

import lombok.extern.slf4j.Slf4j;

@Service
@Slf4j
public class TestProducerBizImpl implements TestProducerService{
    @Autowired
    @Qualifier("commonProducer")
    private Producer producer;
    @Autowired
    private TimeoutProcessCore timeoutProcessCore;
    @Override
    public void send() {
        ApiDatabaseBo apiDatabaseDto = new ApiDatabaseBo();
        apiDatabaseDto.setDatabaseCode("jeeyt");
        apiDatabaseDto.setDatabaseName("数据库");
        SendResult result;
        log.info("开始生产调整消息事件，参数为:{}", GsonUtil.objectToJsonString(apiDatabaseDto));
        String topic = "testTopic";
        String tag = "934";
        /**公共事件发送*/
        result = producer.send(topic, tag, topic + "|" + tag, apiDatabaseDto);
        log.info("生产事件结束，生产结果为:{}", result);
        if (!SendStatus.SEND_OK.equals(result.getSendStatus())) {
            log.info("生产事件失败，开始重新生产");
            timeoutProcessCore.retryProducer(apiDatabaseDto, topic, tag);
        }
    }
}
